<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
			$id=intval($_RQ['id']);
			if(!$id){
				exi('订单不存在，请重新选择订单','error');
			}	
			$item=pdo_get('jy_qiuyuyue_server_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));   
			$serve=pdo_get('jy_qiuyuyue_serve',array('id'=>$item['serve_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['store']=pdo_get('jy_qiuyuyue_store',array('id'=>$item['store_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['user_name']=$member['nickname'];
			$item['user_mobile']=$member['mobile'];
			$item['serve_title']=$serve['title'];
			$item['serve_image']=$serve['image'];
			$item['plate']=pdo_get('jy_qiuyuyue_serve_plate',array('id'=>intval($item['plate_id']),'uniacid'=>$_SESSION['uniacid']),array('title'));
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			$item['serve_typetitle']=$this->serve_types[$item['serve_type']];
			$weekid=date("w",strtotime($item['day']));
			$weekid=$weekid?:7;
			$serve_time=json_decode($serve['serve_time'],true);
			$timeids=str_array($item['timeid']);
			$serve_times=array();
			foreach($timeids as $tv){
				if(intval($tv)){
					$timekey=$tv;
				}else{
					$timekey=substr($tv, 0, -1);
				}
				$fee=$serve_time[intval($timekey)]['fee']?:$serve['price'];
				if($weekid==6 && $serve['week6_addfee']>0){
					$fee +=$serve['week6_addfee'];
				}
				if($weekid==7 && $serve['week7_addfee']>0){
					$fee +=$serve['week7_addfee'];
				}
				if($item['is_ban']){
					$fee=50*$fee/100;
				}
				$serve_times[]=array(
					'times'=>$serve_time[intval($timekey)]['times'],
					'fee'=>$fee,
					'id'=>$tv,
				);
			}
			$item['serve_times']=$serve_times;
			$item['ordersnurl']=custom_url('jy_qiuyuyue/manage.hexiao//ordersn='.$item['ordersn'],true);
			if($item['status']==1){
				$item['can_refund']=1;
			}
			$item['statustitle']=$this->order_status[$item['status']];
			$item['users']=$item['users']?json_decode($item['users'],true):array();
			$return['item']=$item;
			$post=$this->pdo_get('pingjia',array('order_id'=>intval($item['id']),'store_id'=>intval($item['store_id']),'good_id'=>intval($item['serve_id'])));
			if(!$post){
				$post=array(
					'order_id'=>intval($item['id']),
					'good_id'=>intval($item['serve_id']),
					'store_id'=>intval($item['store_id']),
					'star'=>5,
					'fuwustar'=>5,
				);
			}
			$post['images']=json_decode($post['images'],true);
			$return['post']=$post;
			set_html('title','评论');
			exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'msg'=>$postdata['msg'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
		'fuwustar'=>intval($postdata['fuwustar']),
	);
	$comment_id=$this->pdo_getcolumn('pingjia',array('order_id'=>intval($postdata['order_id']),'store_id'=>intval($postdata['store_id']),'good_id'=>intval($postdata['good_id'])),'id');
	$show=$shopset['iscomment']?0:1;
	if($comment_id){
		if($postdata['is_show']==1){
			exi('该评价已生效显示，不可修改！','error','goback');
		}
		$this->pdo_update('pingjia',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'is_show'=>$show,
			'order_id'=>intval($postdata['order_id']),
			'good_id'=>intval($postdata['good_id']),
			'store_id'=>intval($postdata['store_id']),
			'type'=>2,
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('pingjia',$data);
		$this->update('server_order',array('iscomment'=>1),array('id'=>$insert['order_id'],'uniacid'=>$_SESSION['uniacid']));
	}
	exi('评价成功！','','goback');
}
?>